package thread;

/*
 * @author zzr
 * @date: 2025/04/15  16:21
 * @description:
 */
public class Thread13 {
    public static void main(String[] args) {

        Object locker1 = new Object();
        Object locker2 = new Object();
        Thread t1 = new Thread(() -> {
            synchronized (locker1) {
                System.out.println("线程 1 拿到 locker1 ");

                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

                synchronized (locker2) {
                    System.out.println("线程 1 拿到 locker 1 和 locker2");
                }
            }
        });

        Thread t2  = new Thread(() -> {
            synchronized (locker1) {
                System.out.println("线程 2 拿到 locker1");

                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

                synchronized (locker2) {
                    System.out.println("线程 2 拿到 locker1 和 locker2");
                }
            }
        });
        t1.start();
        t2.start();
    }
}
